<template>
  <el-row class="warp dashboard-editor-container">
    <el-col :span="24" class="warp-breadcrum ">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }"><b>首页</b></el-breadcrumb-item>
      </el-breadcrumb>
    </el-col>
    <!-- <el-col :span="24" class="warp-main">
      <section class="chart-container">
        <el-row>
          <el-col :span="8">
            <el-card :body-style="{ padding: '0px' }">
              <img src="../assets/images/forest.png" class="image">
              <div style="padding: 14px;">
                <span>当前区块高度</span>
                <div class="bottom clearfix">
                  <time class="time">{{ blockHeightwithdraw }}</time>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card :body-style="{ padding: '0px' }">
              <img src="../assets/images/sunrise.png" class="image">
              <div style="padding: 14px;">
                <span>区块高度</span>
                <div class="bottom clearfix">
                  <time class="time">{{ blockHeightTx }}</time>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card :body-style="{ padding: '0px' }">
              <img src="../assets/images/sunshine.png" class="image">
              <div style="padding: 14px;">
                <span>快乐生活每一天</span>
                <div class="bottom clearfix">
                  <time class="time">{{ currentDate }}</time>
                </div>
              </div>
            </el-card>
          </el-col>-->
          <el-col>
                <el-row>
                  <el-col :span="8">
                      <div id="gauge" style="width:100%; height:300px;"></div>
                  </el-col>
                  <el-col :span="8">
                      <div id="gauge2" style="width:100%; height:300px;"></div>
                  </el-col>
                  <el-col :span="8">
                      <div id="gauge3" style="width:100%; height:300px;"></div>
                  </el-col>
                </el-row>
          </el-col>
           <el-col>
              <div class="info-container">
              <div class="info-wrapper">
                  <el-row>
                    <el-col :span="8">
                      <div class="info-item" :to="'/article/wscnlist?uid='+uid">
                      <countTo class="info-item-num" :startVal='0' :endVal='statisticsData.article_count' :duration='3000'></countTo>
                      <span class="info-item-text">日统计量</span>
                      <wscn-icon-svg icon-class="a" class="dashboard-editor-icon"/>
                     </div>
                    </el-col>
                    <el-col :span="8">
                     <div class="info-item" style="cursor: auto">
                      <countTo class="info-item-num"  :startVal='0' :endVal='statisticsData.pageviews_count' :duration='5000'></countTo>
                      <span class="info-item-text">月统计量</span>
                      <wscn-icon-svg icon-class="b" class="dashboard-editor-icon"/>
                    </div>
                    </el-col>
                    <el-col :span="8">
                       <div class="info-item" :to="'/comment/commentslist?res_author_id='+uid">
                        <countTo class="info-item-num" ref='countTo3' :startVal='0' :endVal='statisticsData.comment_count' :duration='35000'></countTo>
                        <span class="info-item-text">年统计量</span>
                        <wscn-icon-svg icon-class="c" class="dashboard-editor-icon"/>
                      </div>
                    </el-col>
                  </el-row>
              </div>
          </div>
          </el-col>
          <el-col :span="12">
            <div id="chartColumn" style="width:100%; height:400px;"></div>
          </el-col>
          <el-col :span="12">
            <div id="chartBar" style="width:100%; height:400px;"></div>
          </el-col>
          <el-col :span="12">
            <div id="chartLine" style="width:100%; height:400px;"></div>
          </el-col>
          <el-col :span="12">
            <div id="chartPie" style="width:100%; height:400px;"></div>
          </el-col>
          <el-col :span="24">
            <a href="http://echarts.baidu.com/examples.html" target="_blank" style="float: right;">more>></a>
          </el-col>
        </el-row>
      </section>

    </el-col>
  </el-row>
</template>
<style>
  .time {
    font-size: 13px;
    color: #999;
  }

  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .image {
    width: 100%;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both
  }

  .chart-container {
    width: 100%;
  }
  .chart-container .el-col {
    padding: 30px 20px;
  }

    .info-container {
        position: relative;
        margin-left: 190px;
        height: 150px;
        line-height: 200px;
        .display_name {
            font-size: 48px;
            line-height: 48px;
            color: #212121;
            position: absolute;
            width:500px;
            top: 25px;
        }
        .info-wrapper {
            height:40px;
            width:800px;
            line-height: 40px;
            position: absolute;
            bottom: 8px;
            .info-item {
                cursor: pointer;
                display: inline-block;
                margin-right: 95px;
                .info-item-num {
                    color: #212121;
                    font-size: 24px;
                    display: inline-block;
                    padding-right: 5px;
                }
                .info-item-text {
                    color: #727272;
                    font-size: 14px;
                    padding-right: 5px;
                    display: inline-block;
                }
            }
        }
        .dashboard-editor-icon {
            width: 22px;
            height: 22px;
        }


    }
</style>

<script>
  import echarts from 'echarts'
  import API from '../api/api_book';
  import countTo from 'vue-count-to'
  export default {
    name: 'dashboard-editor',
    components: { countTo },
    data() {
      return {
        currentDate: new Date(),
        blockHeightwithdraw: 0,
        blockHeightTx: 0,
        chartColumn: null,
        chartBar: null,
        chartLine: null,
        chartPie: null,
        uid:"",
       statisticsData: {
          article_count: 1000,
          comment_count: 1000,
          pageviews_count:1000
        },
      };
    },
    mounted: function () {
      var _this = this;
      //基于准备好的dom，初始化echarts实例
      this.getBlockHeight();
      this.chartColumn = echarts.init(document.getElementById('chartColumn'));
      this.chartBar = echarts.init(document.getElementById('chartBar'));
      this.chartLine = echarts.init(document.getElementById('chartLine'));
      this.chartPie = echarts.init(document.getElementById('chartPie'));
      this.gauge = echarts.init(document.getElementById('gauge'));
      this.gauge2 = echarts.init(document.getElementById('gauge2'));
      this.gauge3 = echarts.init(document.getElementById('gauge3'));
      console.log(this.blockHeightwithdraw);
      this.chartColumn.setOption({
        title: { text: 'blockchian Height' },
        tooltip: {},
        xAxis: {
          data: ["当前高度", "充值高度", "提现高度"]
        },
        yAxis: {},
        series: [{
          name: '数量',
          type: 'bar',
          data: [10,this.blockHeightwithdraw, 8]
        }]
      });

      this.chartBar.setOption({
        title: {
          text: 'Bar Chart',
          subtext: '数据来自网络'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {
          data: ['2011年', '2012年']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          boundaryGap: [0, 0.01]
        },
        yAxis: {
          type: 'category',
          data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)']
        },
        series: [
          {
            name: '2011年',
            type: 'bar',
            data: [18203, 23489, 29034, 104970, 131744, 630230]
          },
          {
            name: '2012年',
            type: 'bar',
            data: [19325, 23438, 31000, 121594, 134141, 681807]
          }
        ]
      });

      this.chartLine.setOption({
        title: {
          text: 'Line Chart'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['邮件营销', '联盟广告', '搜索引擎']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '邮件营销',
            type: 'line',
            stack: '总量',
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '联盟广告',
            type: 'line',
            stack: '总量',
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: '搜索引擎',
            type: 'line',
            stack: '总量',
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      });

      this.chartPie.setOption({
        title: {
          text: 'Pie Chart',
          subtext: '纯属虚构',
          x: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: [
              { value: 335, name: '直接访问' },
              { value: 310, name: '邮件营销' },
              { value: 234, name: '联盟广告' },
              { value: 135, name: '视频广告' },
              { value: 1548, name: '搜索引擎' }
            ],
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      });
      this.gauge.setOption({

          tooltip : {
                formatter: "{a} <br/>{b} : {c}%"
            },
            toolbox: {
                feature: {
                    restore: {},
                    saveAsImage: {}
                }
            },
            series: [
                {
                    name: '业务指标',
                    type: 'gauge',
                    detail: {formatter:'{value}%'},
                    data: [{value: 50, name: '完成率'}]
                }
            ]
      });
      this.gauge2.setOption({

          tooltip : {
                formatter: "{a} <br/>{b} : {c}%"
            },
            toolbox: {
                feature: {
                    restore: {},
                    saveAsImage: {}
                }
            },
            series: [
                {
                    name: '业务指标',
                    type: 'gauge',
                    detail: {formatter:'{value}%'},
                    data: [{value: 50, name: '完成率'}]
                }
            ]
      });
      this.gauge3.setOption({
        tooltip : {
              formatter: "{a} <br/>{b} : {c}%"
          },
          toolbox: {
              feature: {
                  restore: {},
                  saveAsImage: {}
              }
          },
          series: [
              {
                  name: '业务指标',
                  type: 'gauge',
                  detail: {formatter:'{value}%'},
                  data: [{value: 50, name: '完成率'}]
              }
          ]
      });
    },
    methods: {
      getBlockHeight() {
        let that = this;
        let params = {
        };
        that.loading = true;
        API.getBlockHeight(params).then(function (result) {
          that.loading = false;
          if (result && result.data) {
            that.blockHeightwithdraw = result.data.blockHeightwithdraw;
            that.blockHeightTx = result.data.blockHeightTx;
          }
        }, function (err) {
          that.loading = false;
          that.$message.error({showClose: true, message: err.toString(), duration: 2000});
        }).catch(function (error) {
          that.loading = false;
          console.log(error);
          that.$message.error({showClose: true, message: '请求出现异常', duration: 2000});
        });
      }
    }

  }
</script>
